package com.hxkj.controller;

import com.hxkj.domain.po.FunctionLibrary;
import com.hxkj.domain.po.FunctionLibraryTree;
import com.hxkj.service.FunctionLibraryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @ClassName 功能库控制器
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/6/27 11:18
 * @Version 1.0
 */
@RestController
@RequestMapping(value = "/functionlibrary")
public class FunctionLibraryController {
    @Autowired
    private FunctionLibraryService functionLibraryService;


    /**
     * 保存
     * @param functionLibrary
     * @throws Exception
     */
    @RequiresPermissions("library:add")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public void saveFunctionLibrary(@ModelAttribute FunctionLibrary functionLibrary) throws Exception{
        functionLibraryService.saveFunctionLibrary(functionLibrary);
    }


    /**
     * 修改
     * @param functionLibrary
     * @throws Exception
     */
    @RequiresPermissions("library:modify")
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public void modifyFunctionLibrary(@ModelAttribute FunctionLibrary functionLibrary) throws Exception{
        functionLibraryService.modifyFunctionLibrary(functionLibrary);
    }

    /**
     * 获取功能树
     * @param functionLibrary
     * @return
     * @throws Exception
     */
    @RequiresPermissions("library:view")
    @RequestMapping(value = "/getlisttree", method = RequestMethod.POST)
    public Callable<List<FunctionLibraryTree>> getFunctionLibraryListTree(@ModelAttribute FunctionLibrary functionLibrary) {
        return () -> functionLibraryService.getFunctionLibraryListTree(functionLibrary);
    }


    /**
     * 获取状态启用的功能树
     * @param functionLibrary
     * @return
     */
    @RequiresPermissions("library:view")
    @RequestMapping(value = "/getshowlisttree", method = RequestMethod.POST)
    public Callable<List<FunctionLibraryTree>> getShowFunctionLibraryListTree(@ModelAttribute FunctionLibrary functionLibrary) {
        return () -> functionLibraryService.getShowFunctionLibraryListTree(functionLibrary);
    }


    /**
     * 删除
     * @param functionLibrary
     * @throws Exception
     */
    @RequiresPermissions("library:remove")
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public void removeFunctionLibrary(@ModelAttribute FunctionLibrary functionLibrary) throws Exception{
        functionLibraryService.removeFunctionLibrary(functionLibrary);
    }


    /**
     * 修改
     * @param functionLibrary
     * @throws Exception
     */
    @RequiresPermissions("site:modify")
    @RequestMapping(value = "/functiontosite", method = RequestMethod.POST)
    public void functionToSite(@ModelAttribute FunctionLibrary functionLibrary) throws Exception{
        functionLibraryService.functionToSite(functionLibrary);
    }
}
